//
//  RecordRequestModel.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/12.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON
import HandyJSON

class RecordRequestModel:  NSObject {
    class func loadRecordRequestData(parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [RecordCommendModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_RecommendProgram, jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [RecordCommendModel]()
                let arr = json["data"].arrayValue
                for dic in arr {
                    let model = JSONDeserializer<RecordCommendModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func loadConformData(parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [RecordCommendModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_Conform, jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [RecordCommendModel]()
                let arr = json["data"].arrayValue
                for dic in arr {
                    let model = JSONDeserializer<RecordCommendModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func topMark(parameters:[String : Any], completion:@escaping (_ succeed: Bool) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_TopMark
        , jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                completion(true)
            } else {
                completion(false)
            }
        }
    }
    
    class func loadMyBuyData(completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [ListenListModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_MyBuyRecord, jointArr: nil, parameters: ["startPoint":1,"maxPage":9999,"userId":String.getUserId(),"type":2]) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [ListenListModel]()
                let dic = json["data"].dictionaryValue
                let arr = dic["data"]!.arrayValue
                for dic in arr {
                    let model = JSONDeserializer<ListenListModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }

}
